// 先引入axios
import axios from 'axios';

//配置axios
axios. withCredentials=true;
//歌手排行榜数据
let getList=(id)=>{
   return axios.get(`/api/singer/list/${id}?json=true`)
} 
//歌手歌曲详情数据
let getSingers=(infoID)=>{
    return axios.get(`/api/singer/info/${infoID}&json=true`)
 } 
 //获取歌单里的详情
let getPlistInfo=(specialid)=>{
   return axios.get(`/api/plist/list/${specialid}/?json=true`)
}
//获取歌单数据
let getPlist=()=>{
   return axios.get(`/api/plist/index&json=true`)
}
//获取排行数据
// http://m.kugou.com/rank/list&json=true

let getpHanglist=()=>{
   return axios.get(`/api/rank/list&json=true`)
}
//排行榜下的数据列表
//rank/info/?rankid=8888&page=1&json=true
let getphSonglist=(rankid)=>{
   return axios.get(`/api/rank/info/?rankid=${rankid}&page=1&json=true`)
}
// /proxy/rank/info/?rankid=${infoID}&page=1&json=true
// http://m.kugou.com/?json=true 新歌棒
let newSong=()=>{
   return axios.get(`/api/?json=true`)
}
// http://mobilecdn.kugou.com/api/v3/search/hot?format=json&plat=0&count=30
let searchhot=()=>{
   return axios.get(`/aproxy/api/v3/search/hot?format=json&plat=0&count=30`)
}

//http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=%E7%8E%8B%E5%8A%9B%E5%AE%8F&page=1&pagesize=20&showtype=1


let getkeyword=(keyword)=>{
   return axios.get(`/aproxy/api/v3/search/song?format=json&keyword=${keyword}&page=1&pagesize=20&showtype=1`)
}

//login 

let loginer=(data)=>{
   return axios({
      url:"/login/users/login",
      data:data,
      method:'post',
      headers:{"Content-Type":"application/json"}
   })
}

let register=(data)=>{
   return axios({
      url:"/login/users/regist",
      data:data,
      method:'post',
      headers:{"Content-Type":"application/json"}
   })
}
//请求拦截器
axios.interceptors.request.use(config=>{
   if(config.url=="/login/users/login"||config.url=="/login/users/regist"){
      return config
   }else{
      let token=localStorage.getItem("token")
      config.headers['authorization']=token;
      console.log(config)
      return config
   }
})

const isLogin=()=>{
   return axios.get("/login/users/check")
}
export{
   getList,
   getSingers,
   getPlist,
   getPlistInfo,
   getpHanglist,
   getphSonglist,
   newSong,
   searchhot,
   getkeyword,
   loginer,
   isLogin,
   register
   
}
